package sk.stuba.fiit.repka.dp.main;

import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URI;

import org.mindswap.owl.OWLDataProperty;
import org.mindswap.owl.OWLFactory;
import org.mindswap.owl.OWLIndividualList;
import org.mindswap.owl.OWLKnowledgeBase;
import org.mindswap.owl.OWLOntology;
import org.mindswap.owl.OWLWriter;
//import org.mindswap.owls.process.variable.Output;
import org.mindswap.owls.profile.Profile;
import org.mindswap.owls.service.Service;
import org.mindswap.owls.validator.OWLSValidator;
import org.mindswap.owls.validator.OWLSValidatorReport;
import org.mindswap.utils.URIUtils;
//TODO remove this class
public class TestOWLSAPI {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		createOWLSOntologie();	
//		test();

		   
	}
	
	private static void test() {
		 // create the URI of a known service for us to read in
//		   URI aURI = URI.create("http://on.cs.unibas.ch/owl-s/1.2/ZipCodeFinder.owl");
		
		URI aURI = URI.create("http://www.mindswap.org/2004/owl-s/1.1/BookFinder.owl");
		   

		   // create a knowledge base using the owl factory
		   OWLKnowledgeBase aKB = OWLFactory.createKB();

		   // read in the file specified by the URI into the knowledge base; by default,
		   // this will also read all ontologies imported by the target file
		   OWLOntology aOntology;
		try {
			aOntology = aKB.read(aURI);
			isOWLSValid(aOntology);
			URI bURI = URI.create("http://www.w3.org/2001/XMLSchema#anyURI");
			OWLDataProperty d = aOntology.getDataProperty(bURI);
			// create an output stream to write the ontology to
			   FileOutputStream aOutputStream = new FileOutputStream("write-test.owl");

			   // create a writer from the ontology
			   OWLWriter aWriter = aOntology.getWriter();

			   // write this ontology out to the specified output stream
			   aWriter.write(aOntology, aOutputStream, aOntology.getURI());

			   // alternatively, if we are reading in an OWL-S description we can use
			   // readService(URI) or readAllServices(URI) to get the service or list of
			   // services specified by the URI.

			   // should only be used if we know that the file contains not more than one
			   // service
			   Service aService = aKB.readService(aURI);


			   // if the file has more than one service or we do actually not know how many
			   // it has then we should read the file and query for all service instances
//			   OWLIndividualList<Service> services = aKB.readAllServices(aURI);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	private static void createOWLSOntologie() {
//		URI base = URI.create("http://example.org/test.owl");
//		OWLKnowledgeBase kb = OWLFactory.createKB();
//		OWLOntology ont = kb.createOntology(base);
//		Service service = ont.createService(
//		URIUtils.createURI(base, "Service"));
//		Profile profile = ont.createProfile(
//		URIUtils.createURI(base, "Profile"));
//		service.addProfile(profile);  // MARK
//		Output output = ont.createOutput(
//		URIUtils.createURI(base, "Output"));
//		profile.addOutput(output);
//		isOWLSValid(ont);
//		ont.write(System.out, null);
	}
	
	private static void isOWLSValid(OWLOntology theOntology) {
//		// create a new validator
//		   OWLSValidator aValidator = new OWLSValidator();
//
//		   // the URI of a known service for us to validate
//
//		   // run the validator
//		   OWLSValidatorReport aReport;
//		aReport = aValidator.validate(theOntology);
//		   // print the results to the console
//		aReport.print(System.out);

		
	}

}
